//
// Created by zsj on 2019/12/21.
//

#ifndef SCLI_CRYPTO_ALGORITHM_H
#define SCLI_CRYPTO_ALGORITHM_H

#include <iostream>
#include <string>
#include "../comm/err_ctl.h"
#include "../comm/args.h"

using namespace std;

class crypto_algorithm {
public:
    virtual const string encrypt() = 0;
    virtual const string decrypt() = 0;

    string execute(int mode) {
        if (mode == MODE_DECRYPT) {
            if (cipher.empty()) {
                __err("密文为空。");
            }

            return decrypt();
        } else if (mode == MODE_ENCRYPT) {
            if (plain.empty()) {
                __err("明文为空。");
            }

            return encrypt();
        }
        return "";
    }

    void set_key(const string & _key) {
        this->key = _key;
    }

    void set_plain(const string & _plain) {
        this->plain = _plain;
    }

    void set_cipher(const string &_cipher) {
        this->cipher = _cipher;
    }

    string get_key() {
        return this->key;
    }

    string get_plain() {
        return this->plain;
    }

    string get_cipher() {
        return this->cipher;
    }

protected:
    string key;
    string plain;
    string cipher;
};


#endif //SCLI_CRYPTO_ALGORITHM_H
